home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / test / iddictio.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  93 lines

  1. /* Test class IdentDict
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    iddictio.c,v $
  26.  * Revision 3.0  90/05/20  00:29:16  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/iddictio.c,v 3.0 90/05/20 00:29:16 kgorlen Rel $";
  31.  
  32. #include "Assoc.h"
  33. #include "Bitset.h"
  34. #include "IdentDict.h"
  35. #include "OrderedCltn.h"
  36. #include "Point.h"
  37. #include "Rectangle.h"
  38. #include "Set.h"
  39. #include "SortedCltn.h"
  40. #include "Stack.h"
  41. #include "String.h"
  42. #include "OIOnih.h"
  43.  
  44. Object* testStore()
  45. {
  46.     Bitset& bitset = *new Bitset(Bitset::bit(4)|Bitset::bit(6));
  47.     IdentDict& iddict = *new IdentDict;
  48.     OrderedCltn& orderedcltn = *new OrderedCltn;
  49.     Point& point = *new Point(1,2);
  50.     Rectangle& rect = *new Rectangle(0,1,2,3);
  51.     Set& set = *new Set;
  52.     SortedCltn& sortedcltn = *new SortedCltn;
  53.     Stack& stack = *new Stack;
  54.     String& str = *new String("Hello, world!");
  55.     orderedcltn.add(point); orderedcltn.add(rect); orderedcltn.add(str);
  56.     stack.push(bitset); stack.push(orderedcltn);
  57.     sortedcltn.add(*new String("Huey"));
  58.     sortedcltn.add(*new String("Dewey"));
  59.     sortedcltn.add(*new String("Louie"));
  60.     iddict.add(*new Assoc(orderedcltn,point));
  61.     iddict.add(*new Assoc(bitset,rect));
  62.     iddict.add(*new Assoc(sortedcltn,stack));
  63.     set.add(orderedcltn);
  64.     set.add(stack);
  65.     set.add(sortedcltn);
  66.     set.add(iddict);
  67.     OrderedCltn& monster = *new OrderedCltn;
  68.     monster.add(set); monster.add(*set.deepCopy());
  69.     return &monster;
  70. }
  71.  
  72. #include <fcntl.h>
  73. #include <osfcn.h>
  74.  
  75. main()
  76. {
  77.     cout << "Test storeOn" << endl;
  78.     ostream* out = new ostream(creat("iddicta",0664));
  79.     Object* a = testStore();
  80.     a->storeOn(OIOnihout(*out));
  81.     delete out;
  82.  
  83.     cout << "Test readFrom" << endl;
  84.     istream* in = new istream(open("iddicta",O_RDONLY));
  85.     Object* b = Object::readFrom(OIOnihin(*in));
  86.     delete in;
  87.     cout << "*** object stored:" << endl << *a << endl;
  88.     cout << "*** object read:" << endl << *b << endl;
  89.     out = new ostream(creat("iddictb",0664));
  90.     b->storeOn(OIOnihout(*out));
  91.     delete out;
  92. }
  93.